<?php

class MessageResponse {
	private $id;
	private $id_message;
	private $id_user;
	private $text;
	private $date;
	
	function __construct($id,$id_message, $id_user, $text, $date){
		$this -> id = $id;
		$this -> id_message = $id_message;
		$this -> id_user = $id_user;
		$this -> text = $text;
		$this -> date = $date;

	}

	function getMessageReponse($db,$id){
		$result=$db->query("SELECT * FROM message_response WHERE mr_IDreponse = $id",2);
		$message_response=new MessageResponse(	$result[0]['mr_IDresponse'],
						$result[0]['mr_id_message'], 
						$result[0]['mr_id_user'],
						$result[0]['mr_text'],
						$result[0]['mr_date']);
				
		return $message_response;
	
	}
	
	function insertMessageRespobse($db,$message_response){
		$ID 		= $message_response -> getID();
		$id_message	= $message_response -> getIdMessage();
		$id_user 	= $message_response -> getIdUser();
		$text 		= $message_response -> getText();
		$date 		= $message_response -> getDate();
		
		
		$result=$db->insert("INSERT INTO message_response (mr_IDreponse,mr_id_message,mr_id_user, mr_text, mr_date)
										 VALUES($ID,$id_message,$id_user,'$text',now())");
		return $result;
	}		
	
	
	function updateMessageRespons($db,$message_response)
	{
		$ID 		= $message_response -> getID();
		$id_message	= $message_response -> getIdMessage();
		$id_user 	= $message_response -> getIdUser();
		$text 		= $message_response -> getText();
		$date 		= $message_response -> getDate();
		
		
		$result=$db->update("UPDATE  message_response SET mr_id_message = $id_message, mr_id_user = $id_user, mr_text = '$text')
				
		return $result;
				
	}
	
	function deleteMessageResponse($db,$message_response)
	{
		$ID 		= $message_response -> getID();
		
		$result=$db->delete("DELETE FROM message_response WHERE mr_IDreponse=$ID");
				
		return $result;
	}
			
	
	function getID(){
		return $this -> id;
	}	
	
	function  setID($id){
		$this -> id = $id;
	}	
	
	
	function getIdMessage(){
		return $this -> id_message;
	}	
	
	function  setIdMessage($id_message){
		$this -> id_message = $id_message;
	}	
	
			
	function getIdUser(){
		return $this -> id_user;
	}
	
	function  setIdUser($id_user){
		$this -> id_user = $id_user;
	}
	
	
	
	function getText(){
		return $this -> text;
	}
	
	function setText($text){
	  $this -> text = $text;
	}
	

	function getDate(){
		return $this -> date;
	}
	
	function setDate($date){
		$this -> date = $date;
	}
	
}
?>